﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.IO;
using BLL;
using BLL.教师操作BLL;
using Model;
using System.Timers;

namespace NCRE学生考试端V1._0.验证码登录
{
    public partial class frmQRcode : Form
    {
        bool textboxValid = true; //ip设置使用变量
        public frmQRcode()
        {

            InitializeComponent();
            System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;  
            //用于解决线程间操作无效：从不是创建控件"textBox1"的线程访问它
        }

        private List<ScoreAdornEntity> scoreadorn = new List<ScoreAdornEntity>();


        #region 窗体单一显示-李金颖-2018-12-8 11:59:14
        private static frmQRcode FrmQRcode = null;
        public static frmQRcode GetInstance()
        {
            if (FrmQRcode == null || FrmQRcode.IsDisposed)
            {
                FrmQRcode = new frmQRcode();
            }
            return FrmQRcode;

            
        }

        #endregion


        #region 学号自动录入并显示-白爱民-2018-12-20 ：21：22：23
        /// <summary>
        /// 学号自动添加到数据库
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void txtUserID_TextChanged(object sender, EventArgs e)
        {
            //判断文本框是否达到11位数字，如果不是则返回
            if (txtUserID.Text.Length<11)
            {
                return;
            }

            //实例化窗体：studentinfoentity
            StudentInfoEntity stu = new StudentInfoEntity();
            stu.studentID = txtUserID.Text.Trim();//将窗体文本框赋值给实体

            //实例化BLL层对应界面
            QRcodeBLL qucode = new QRcodeBLL();

            string checkCode = GenCode(4); // 产生4位随机字符                 
            stu.code = checkCode; //调取随机数方法，并赋值：   

            //GlobaData.code = checkCode;

                      
            bool flag = qucode.UpdateStudentInfo(stu);//添加至数据库  

            if(flag == true)
            {
                //lblShowMessage.Text = "";
                viewdata();//调取方法，datagridview显示数据；

                txtUserID.Clear();//清空文本框

                #region 连接公众号接口——薛帅行 12月20号16点37分
                StudentInfo studentInfo = new StudentInfo();

                #region 根据学号查询相关信息 薛帅行 12月20号20点41分
                //stu.studentID = txtUserID.Text.Trim();
                DataTable table = qucode.SelectStudentByID(stu);
                #endregion


                #region 赋值字段
                studentInfo.EventName = checkCode; //将验证码赋值
                studentInfo.UserCode = stu.studentID;
                studentInfo.UserId = stu.studentID;  //根据templateId和UserId推送给公众号消息；
                studentInfo.UserName = Convert.ToString(table.Rows[0]["studentName"]);
                #endregion

                //GlobaData.userId = stu.studentID;
                //studentInfo.Profession = "土木";
                //studentInfo.pushEndTime = "2018-12-19 10:01:15";
                //studentInfo.pushStartTime = "2018-12-19 10:01:15";

                #region 必传字段和反序列化--不可更变
                studentInfo.ClassName = "土木";
                studentInfo.ConfirmType = "0";
                studentInfo.TemplateId = "OZuUS9TKmg5IXpY0fGPC3gI65ie72k3GEDn1zY_dxbE";  //绑定公众号后公众号库有消息；模板ID；

                
                string result = IRestful.RestfulAdd(new Resful.Serialize().Serialize1(studentInfo));
                //将获取的数据反序列化
                LoginEntity loginEntity = new Resful.Serialize().Deserialize(result);
                UserData userdata = loginEntity.loginModel;
                #endregion

                #endregion
            }
            else
            {
                //MessageBox.Show("没有该学生，请重新扫码!");
                //lblShowMessage.Text = "没有该学生，请重新扫码!";
                //txtUserID.SelectAll();
                txtUserID.Text = "";
                txtUserID.Focus();
            }


       }
        #endregion


        #region 生成4位随机数-苑仁杰-2018-12-20 ：21：22：23
        /// <summary>
        /// 产生随机字符串
        /// </summary>
        /// <param name="num">随机出几个字符</param>
        /// <returns>随机出的字符串</returns>
        private string GenCode(int num)
        {
            string str = "0123456789";
            char[] chastr = str.ToCharArray();
            string code = "";
            Random rd = new Random();
            int i;
            for (i = 0; i < num; i++)
            {
                code += str.Substring(rd.Next(0, str.Length), 1);
            }
            return code;

        }





        #endregion


        #region 初始加载信息--白爱民--2019年1月4日15:18:57
        private void frmQRcode_Load(object sender, EventArgs e)
        {
            
            dataGridView1.DataSource = ""; //初始加载后datagridview清空
            timer1.Enabled = true;

            #region 5分钟定时更新事件——薛帅行——2018年12月28日19:16:13
            System.Timers.Timer timer = new System.Timers.Timer();
            timer.Enabled = true;
            timer.Interval = 120000; //执行间隔时间,单位为毫秒; 这里实际间隔为2分钟 
            //timer.Interval = 3000;  //测试时间是3秒钟            
            timer.Start();
            timer.Elapsed += new System.Timers.ElapsedEventHandler(test);
            #endregion

        }
        #endregion

        #region 按照学号显示信息-白爱民-2018-12-20:13:27:52 现在删除了
        /// <summary>
        /// 按照学号查询信息显示出来
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        //private void btnInquriy_Click(object sender, EventArgs e)
        //{
        //    //白爱民修改：删除掉学号显示信息功能--2018年12月20日-21点33分

        //    studentinfoentity stu = new studentinfoentity();
        //    stu.studentid = txtinquriyusername.text.trim();
        //    qrcodebll qr = new qrcodebll();
        //    datatable table = qr.selectstudentbyid(stu);

        //    datagridview1.datasource = "";//清空datagridview中的值
        //    datagridview1.datasource = table;//将数据库返回的datatable类型的变量传给datagridview显示
        //    datagv();//调取自动调整datagridview

        //}
        #endregion

        #region 刷新-白爱民-2018-12-20:13:11:26
        /// <summary>
        /// 刷新按钮--将datagridview数据按照验证码重新显示出来
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnBreak_Click(object sender, EventArgs e)
        {
            viewdata();//调取显示datagridview数据
        }
        #endregion


        #region 用datagridview显示存在验证码信息-白爱民-2018-12-20：13:04:02
        private void viewdata()
        {
            //实例化BLL层对应界面
            QRcodeBLL qucode = new QRcodeBLL();

            DataTable table = qucode.getStudentInfo();

            dataGridView1.DataSource = "";//清空DataGridView中的值
            dataGridView1.DataSource = table;//将数据库返回的DataTable类型的变量传给DataGridView显示

            dataGridView1.AllowUserToAddRows = false;//取消最后一行空白格

            //自动调整显示的大小
            dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
            dataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;

            //显示边框
            dataGridView1.CellBorderStyle = DataGridViewCellBorderStyle.Single;
            //居中显示内容
            dataGridView1.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;

            //设置标题为一下名称
            dataGridView1.Columns[0].HeaderText = "学号";
            dataGridView1.Columns[1].HeaderText = "考场";
            dataGridView1.Columns[2].HeaderText = "姓名";
            dataGridView1.Columns[3].HeaderText = "年级";
            dataGridView1.Columns[4].HeaderText = "验证码";

            //dataGridView1.ReadOnly = true;//设置datagridview只读，程序也不可以更改
            dataGridView1.EditMode = DataGridViewEditMode.EditProgrammatically;//设置只读（用户不可手动修改，但是可以通过调用datagridvie.BeginEdit方法进行程序修改）            



        }
        #endregion
       

        #region 用datagridview显示未推送数据--白爱民--2019年1月4日16:09:50
        public void DisplayPushData()
        {
            QRcodeBLL qucode = new QRcodeBLL();
            DataTable table = qucode.SelectScoreAdornDisplayData();

            dataGridView1.DataSource = "";//清空DataGridView中的值
            dataGridView1.DataSource = table;//将数据库返回的DataTable类型的变量传给DataGridView显示

            dataGridView1.AllowUserToAddRows = false;//取消最后一行空白格

            //自动调整显示的大小
            dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
            dataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;

            //显示边框
            dataGridView1.CellBorderStyle = DataGridViewCellBorderStyle.Single;
            //居中显示内容
            dataGridView1.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;

            //设置标题为一下名称
            dataGridView1.Columns[0].HeaderText = "学号";
            dataGridView1.Columns[1].HeaderText = "姓名";
            dataGridView1.Columns[2].HeaderText = "成绩";
            dataGridView1.Columns[3].HeaderText = "时间";
            dataGridView1.Columns[4].HeaderText = "1为未推送";

            //dataGridView1.ReadOnly = true;//设置datagridview只读，程序也不可以更改
            dataGridView1.EditMode = DataGridViewEditMode.EditProgrammatically;//设置只读（用户不可手动修改，但是可以通过调用datagridvie.BeginEdit方法进行程序修改）            

        }

        #endregion


        #region 推送公众号消息--白爱民--2019年1月4日15:18:11
        private void btnPushMessage_Click(object sender, EventArgs e)
        {
            //判断是否交卷，只有交卷才能推送
            //交卷的时候把值存给数据库；UserID、UserName、UserCode、TotalScore、TotalScoreRanking、MultipleChoiceRanking、PPTRanking、IERanking、是否交卷
            //交卷只能交卷一次
            //推送消息需要全部推送；
            //查询当天的所有已经交卷的记录
            //遍历查询记录

            DisplayPushData();//显示未推送数据

            #region 推送成绩消息返回给公众号——薛帅行——2018年12月21号13点31分
            PushGrades push = new PushGrades();
            push.push();
            #region 注释代码
            //#region 必传字段
            //Score score1 = new Score();
            //score1.ClassName = "二班";
            //score1.ConfirmType = "0";
            //score1.TemplateId = "9Y-jur5cSChkNukxwunopP5idROtxrUkU9OX9UdR36I";
            //score1.EventName = "一级练习";
            ////score1.UserId = FrmLogin.studentID;
            //ScoreAdornEntity score = new ScoreAdornEntity();
            ////score.userId = "15140142035";    
            //#endregion

            //TypeSumFrationBll addScoreAdorn = new TypeSumFrationBll();
            //QRcodeBLL qucode = new QRcodeBLL();

            ////scoreadorn = addScoreAdorn.inquiryScoreAdorn_Isinput(score);//按照交卷查询出所有

            ////查询当天时间并且没有推送出去所有字段
            //DataTable dt = addScoreAdorn.inquiryScoreAdorn(score);

            ////查询当天人次练习模式下所有学生个数
            //DataTable table = qucode.SelectScoreAdornAllday();

            ////将每个人的成绩都推送出去的循环
            //for (int i = 0; i < dt.Rows.Count; i++)
            //{
            //    #region 查询分数排名的方法——薛帅行——2018年12月18点32分                            
            //    QRcodeBLL studentscoreAdornbll = new QRcodeBLL();
            //    int a = 0;//用于赋值当前人次排名
            //    ScoreAdornEntity scoreAdornEntity = new ScoreAdornEntity();
            //    score.userId = Convert.ToString(dt.Rows[i]["userId"]);
            //    //按照学号查询成绩
            //    //查询该学生各项目考试成绩                
            //    scoreAdornEntity.userId = dt.Rows[i][0].ToString();
            //    //DataTable table = studentscoreAdornbll.SelectScoreAdornOrder(scoreAdornEntity);
            //    if (dt.Rows.Count != 0)
            //    {
            //        //总分排名
            //        Single sin = Convert.ToSingle(dt.Rows[i]["totalScore"]);
            //        scoreAdornEntity.totalScore = sin;
            //        //scoreAdornEntity.totalScore =Convert.ToString(dt.Rows[i]["totalScore"]).ToString();
            //        DataTable dtorder = studentscoreAdornbll.SelectScoreAdornOrder(scoreAdornEntity);//查询当天比自己成绩大的信息
            //        a = dtorder.Rows.Count + 1;  //第几名


            //    }
            //    else { }
            //    #endregion

            //    //score1.UserId = FrmLogin.studentID;
            //    score1.UserId = Convert.ToString(dt.Rows[i]["userId"]);
            //    score1.UserName = Convert.ToString(dt.Rows[i]["userName"]);
            //    score1.UserCode = Convert.ToString(dt.Rows[i]["userCode"]);
            //    score1.TotalScore = Convert.ToString(dt.Rows[i]["totalScore"]);
            //    score1.TotalScoreRanking = Convert.ToString(a);

            //    #region score1其他的信息注释
            //    //score1.MultipleChoiceRanking = Convert.ToString(dt.Rows[0]["multipleChoiceRanking"]);
            //    //score1.WindowsRanking = Convert.ToString(dt.Rows[0]["WindowsRanking"]);
            //    //score1.WordRanking = Convert.ToString(dt.Rows[0]["WordRanking"]);
            //    //score1.ExcelRanking = Convert.ToString(dt.Rows[0]["ExcelRanking"]);
            //    //score1.PPTRanking = Convert.ToString(dt.Rows[0]["PPTRanking"]);
            //    //score1.IERanking = Convert.ToString(dt.Rows[0]["IERanking"]);

            //    //content.IERanking = Convert.ToDouble(IE).ToString("0.0");
            //    //score1.EventName = "{\"考试成绩\": \"score1.TotalScore\",\"总成绩排名\": score1.TotalScoreRanking,\"选择题排名\": \"score1.MultipleChoiceRanking\",\"Windows题排名\": \"score1.WindowsRanking\",\"Word题排名\":\"score1.WordRanking\",\"Excel题排名\":\"score1.ExcelRankin\",\"PPT题排名\": \"score1.PPTRanking\",\"IE题排名\": \"score1.IERanking\"}";
            //    //score1.EventName = "{\"totalScore\":\"100\",\"totalScoreRanking\":\"20\",\"multipleChoiceRanking\":\"20\",\"windowsRanking\":\"20\",\"wordRanking\":\"20\",\"excelRanking\":\"20\",\"PPTRanking\":\"20\",\"IERanking\":\"20\"}";

            //    //{"totalScore":"100","totalScoreRanking":"20","multipleChoiceRanking":"20","windowsRanking":"20","wordRanking":"20","excelRanking":"20","PPTRanking":"20","IERanking":"20"};
            //    //score1.EventContent = 

            //    #endregion

            //    string b1 = table.Rows[0][0].ToString(); //用于将当天的练习人次赋值

            //    Content1 content = new Content1();

            //    content.TotalScore = Convert.ToDouble(dt.Rows[i]["totalScore"]).ToString("0.0");
            //    content.TotalScoreRanking = Convert.ToString(a) + ",  " + "当天练习:"+Convert.ToString(b1)+"人次 。" ;
            //    content.MultipleChoiceRanking = Convert.ToDouble(dt.Rows[i]["multipleChoeceRanking"]).ToString("0.0");  //保留小数点后两位
            //    content.WindowsRanking = Convert.ToDouble(dt.Rows[i]["WindowsRanking"]).ToString("0.0");
            //    content.WordRanking = Convert.ToDouble(dt.Rows[i]["WordRanking"]).ToString("0.0");
            //    content.ExcelRanking = Convert.ToDouble(dt.Rows[i]["ExcelRanking"]).ToString("0.0");
            //    content.PPTRanking = Convert.ToDouble(dt.Rows[i]["PPTRanking"]).ToString("0.0");
            //    content.IERanking = Convert.ToDouble(dt.Rows[i]["IERanking"]).ToString("0.0");


            //    #region 分项成绩合格与不合格判断——薛帅行——2018年12月22号08点55分
            //    string message;
            //    //string message1;
            //    //string message2;
            //    //string message3;
            //    //string message4;
            //    //string message5;
            //    //string message6;
            //    if (Convert.ToInt32(dt.Rows[0]["multipleChoeceRanking"]) > 12 && Convert.ToInt32(dt.Rows[0]["WordRanking"]) > 15 && Convert.ToInt32(dt.Rows[0]["ExcelRanking"]) > 15 && Convert.ToInt32(dt.Rows[0]["WindowsRanking"]) > 6 && Convert.ToInt32(dt.Rows[0]["IERanking"]) > 6 && Convert.ToInt32(dt.Rows[0]["PPTRanking"]) > 6)
            //    {
            //        message = "测试非常优秀，但是不要骄傲!";
            //    }
            //    else
            //    {
            //        message = "测试成绩还有更大的提升空间，请再接再励!";
            //    }
            //    //message1,message2,message3,message4,message5,message6还有更大的提升空间，请再接再厉!

            //    #endregion
            //    content.Content = message;

            //    score1.EventContent = content;


            //    string result = IRestful.RestfulAdd(new Resful.EndSerialize().Serialize1(score1));
            //    //将获取的数据反序列化
            //    LoginEntity loginEntity1 = new Resful.Serialize().Deserialize(result);
            //    UserData userdata1 = loginEntity1.loginModel;


            //    //将获取的数据反序列化
            //    LoginEntity loginEntity = new Resful.Serialize().Deserialize(result);
            //    UserData userdata = loginEntity.loginModel;
            //    #endregion
            //    #region 修改推送字段改为已推送--白爱民--2018年12月26日13:06:14
            //    addScoreAdorn.UpdateScoreAdorn(score);
            //    #endregion
            #endregion
            #endregion
            MessageBox.Show("推送成绩完毕");

        }

        #endregion

        #region 刷新未推送消息--白爱民--2019年1月4日16:26:11
        private void btnBtreakPush_Click(object sender, EventArgs e)
        {
            DisplayPushData();
        }

        #endregion

        #region 查询考场空余座位数-刘檬-2018年12月28日19:49:46
        public void test(object source, ElapsedEventArgs e)
        {
            //实例化BLL层对应界面
            QRcodeBLL qucode = new QRcodeBLL();

            //考场剩余座位
            StudentBindPaperTypeEntity StudentBindPaperType = new StudentBindPaperTypeEntity();
            StudentBindPaperType.IP = ipAddressString();
            DataTable dt = qucode.SelectByIP(StudentBindPaperType);

            textBox1.Text = textBox4.Text.Trim() + "剩余座位数：" + (Convert.ToInt32 (txtSetNum.Text.Trim()) - Convert.ToInt32(dt.Rows[0][0]));
            string a = (Convert.ToInt32(txtSetNum.Text.Trim()) - Convert.ToInt32(dt.Rows[0][0])).ToString();
            if (Convert.ToInt32(a) < 0)//限制最少剩余座位数为0
            {
                a = (0).ToString();
            }
            #region 查询师院五楼可用位置

            OnLine online = new OnLine();
            online.ComputerCount = a;
            online.RoomName = "数理楼";
            online.RoomNo = textBox4.Text.Trim();

            string testStr = new Resful.EndSerialize().OnLineSerialize(online);
            testStr = "[" + testStr  + "]";
            string result = IRestful.OnlineRestful(testStr);
            #endregion
        }

        //隐藏考场剩余位置数功能
        private void frmQRcode_Click(object sender, EventArgs e)
        {
            groupBox1.Visible = false;
        }
        //显示考场剩余位置数功能
        private void frmQRcode_DoubleClick(object sender, EventArgs e)
        {
            groupBox1.Visible = true;
        }
        #endregion

        #region ip1段限制输入1-233
        private void txtip1_TextChanged(object sender, EventArgs e)
        {
            int len = txtip1.Text.Length;
            if (len == 3)
            {
                string currentstr = txtip1.Text;
                int currentNum = Convert.ToInt32(currentstr);
                if (currentNum > 223)
                {
                    //无效
                    textboxValid = false;
                    txtip1.Text = "223";
                    SendKeys.Send("{Tab}");
                }
                else if (currentNum == 0)
                {
                    //无效
                    textboxValid = false;
                    txtip1.Text = "1";
                }
                else
                {
                    if (textboxValid)
                    {
                        SendKeys.Send("{Tab}");
                    }
                    else
                    {
                        txtip1.SelectionStart = 0;
                        textboxValid = true;
                    }
                }
            }
           
        }
        #endregion

        #region ip段2,3,4限制输入到255
        //ip段2,3,4限制输入到255,公用方法
        private void textBoxOnTextChanged(object sender, EventArgs e)
        {
            TextBox textBox = sender as TextBox;
            int len = textBox.Text.Length;
            if (len == 3)
            {
                string currentStr = textBox.Text;
                int currentNum = Convert.ToInt32(currentStr);
                if (currentNum > 255)
                {
                    //无效
                    textboxValid = false;
                    textBox.Text = "255";
                }
                else
                {
                    if (textboxValid)
                    {
                        if(textBox == textBox4)
                        { return; }
                        else
                        { SendKeys.Send("{Tab}"); }
                    }
                    else
                    {
                        textBox.SelectionStart = 0;
                        textboxValid = true;
                    }
                }
            }
        }

        private void txtip2_TextChanged(object sender, EventArgs e)
        {
            textBoxOnTextChanged(sender, e);
        }

        private void txtip3_TextChanged(object sender, EventArgs e)
        {
            textBoxOnTextChanged(sender, e);
        }

        private void txtip4_TextChanged(object sender, EventArgs e)
        {
            textBoxOnTextChanged(sender, e);
        }
        #endregion

        #region ip限制输入内容为数字

        //限制输入内容给数字，公用方法
        private void textBoxOnKeyPress(KeyPressEventArgs e)
        {
            if ((e.KeyChar >= '0' && e.KeyChar <= '9') || e.KeyChar == (char)8)
            {
                if (e.KeyChar == (char)8)
                {
                    e.Handled = false;
                    return;
                }
            }
            else
            {
                e.Handled = true;
            }
        }

        private void txtip1_KeyPress(object sender, KeyPressEventArgs e)
        {
            textBoxOnKeyPress(e);
        }

        private void txtip2_KeyPress(object sender, KeyPressEventArgs e)
        {
            textBoxOnKeyPress(e);
        }

        private void txtip3_KeyPress(object sender, KeyPressEventArgs e)
        {
            textBoxOnKeyPress(e);
        }        
        private void txtip4_KeyPress(object sender, KeyPressEventArgs e)
        {
            textBoxOnKeyPress(e);
        }
        #endregion

        #region 对输入的上、下、左、右箭头设置
        private void textBoxOnKeyDown(object sender, KeyEventArgs e)
        {
            TextBox textbox = sender as TextBox;
            if (e.KeyValue == 37 || e.KeyValue == 38 || e.KeyValue == 8)//37:左箭头 38：上箭头 8：BACKSPACE 键
            {
                if (textbox.SelectionStart == 0)//光标后字符索引，从0开始
                {
                    SendKeys.Send("{Tab}");//效果输入Tab键
                }
            }
            else if (e.KeyValue == 39 || e.KeyValue == 40)//39:右箭头 40：下箭头
            {
                string currentStr = textbox.Text;
                if (textbox.SelectionStart == currentStr.Length)
                {
                    SendKeys.Send("+{Tab}{End}");
                }
            }
        }

        private void txtip1_KeyDown(object sender, KeyEventArgs e)
        {
            textBoxOnKeyDown(sender, e);
        }

        private void txtip2_KeyDown(object sender, KeyEventArgs e)
        {
            textBoxOnKeyDown(sender, e);
        }

        private void txtip3_KeyDown(object sender, KeyEventArgs e)
        {
            textBoxOnKeyDown(sender, e);
        }

        private void txtip4_KeyDown(object sender, KeyEventArgs e)
        {
            textBoxOnKeyDown(sender, e);
        }
        #endregion

        #region 获得ip
        public string ipAddressString()
        {
            string ipAddress = txtip1.Text.Trim() + "." + txtip2.Text.Trim() + "." + txtip3.Text.Trim() + "." ;
            return ipAddress;
        }


        #endregion

        #region 推送全部验证码--白爱民2019年1月6日15:36:16
        private void btnPushCode_Click(object sender, EventArgs e)
        {
            viewdata();//调取显示datagridview数据

            //用于查询数据库中有验证码的信息
            QRcodeBLL qucode = new QRcodeBLL();
            DataTable dt = qucode.getStudentInfo();

            if (dt.Rows.Count==0)
            {
                MessageBox.Show("没有可推送验证码信息");
                return;
            }

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                //实例化窗体：studentinfoentity
                StudentInfoEntity stu = new StudentInfoEntity();
                stu.studentID = dt.Rows[i]["studentID"].ToString();//将窗体文本框赋值给实体

                #region 连接公众号接口——薛帅行 12月20号16点37分
                StudentInfo studentInfo = new StudentInfo();

                //#region 根据学号查询相关信息 薛帅行 12月20号20点41分
                ////stu.studentID = txtUserID.Text.Trim();
                //DataTable table = qucode.SelectStudentByID(stu);
                //#endregion


                #region 赋值字段
                studentInfo.EventName = dt.Rows[i]["code"].ToString(); //将验证码赋值
                studentInfo.UserCode = stu.studentID;
                studentInfo.UserId = stu.studentID;  //根据templateId和UserId推送给公众号消息；
                studentInfo.UserName = Convert.ToString(dt.Rows[i]["studentName"]);
                #endregion

                #region 注释代码
                //GlobaData.userId = stu.studentID;
                //studentInfo.Profession = "土木";
                //studentInfo.pushEndTime = "2018-12-19 10:01:15";
                //studentInfo.pushStartTime = "2018-12-19 10:01:15";
                #endregion

                #region 必传字段和反序列化--不可更变
                studentInfo.ClassName = "土木";
                studentInfo.ConfirmType = "0";
                studentInfo.TemplateId = "OZuUS9TKmg5IXpY0fGPC3gI65ie72k3GEDn1zY_dxbE";  //绑定公众号后公众号库有消息；模板ID；


                string result = IRestful.RestfulAdd(new Resful.Serialize().Serialize1(studentInfo));
                //将获取的数据反序列化
                LoginEntity loginEntity = new Resful.Serialize().Deserialize(result);
                UserData userdata = loginEntity.loginModel;
                #endregion

                #endregion
            }
            MessageBox.Show("推送验证码完毕");
        }

        #endregion
    }

}
